#include "cv.h" 
#include "cxcore.h" 
#include "highgui.h"

#include <stdio.h>
void PrintMatrix(CvMat *Matrix, int Rows, int Cols,char* name); 
float Coordinates[4]={1,0,0,3};
int main()
{
	/*IplImage* image2= cvLoadImage ("lena.jpg",CV_LOAD_IMAGE_COLOR);*/  
//	IplImage* image2= cvLoadImage ("lena.jpg",CV_LOAD_IMAGE_GRAYSCALE);
	CvMat *imageMat= cvCreateMat(2,2,CV_32FC1);
	CvMat *evects= cvCreateMat(2,2,CV_32FC1);
	CvMat *evals= cvCreateMat(1,2,CV_32FC1);
	cvSetData(imageMat,Coordinates,imageMat->step);
	PrintMatrix(imageMat,imageMat->rows,imageMat->cols,"imagemat");
	cvEigenVV(imageMat,evects,evals,10,-1,-1);
	PrintMatrix(evects,evects->rows,evects->cols,"evects"); 
	PrintMatrix(evals,evals->rows,evals->cols,"evals"); 

	PrintMatrix(imageMat,imageMat->rows,imageMat->cols,"imagemat");
 
//	cvConvert(image2,imageMat);
	CvMat *eigenvalues = cvCreateMat(1,2,CV_32FC1);
	CvMat *avgvector = cvCreateMat(1,2,CV_32FC1);
	CvMat *eigenvector= cvCreateMat(2,2,CV_32FC1);
	cvCalcPCA(imageMat,avgvector,eigenvalues,eigenvector,CV_PCA_DATA_AS_ROW);
//	printf("hello cv\n"); 
//	printf("image2-height:%d\n",image2->height);
	PrintMatrix(eigenvector,eigenvector->rows,eigenvector->cols,"eigenvector"); 
	PrintMatrix(avgvector,avgvector->rows,avgvector->cols,"avg"); 
	PrintMatrix(eigenvalues,eigenvalues->rows,eigenvalues->cols,"eigenvalues"); 
//	cvNamedWindow("wndname", 1 );  
//	cvShowImage("wndname",image2);  
//	cvWaitKey(0);  
	return 0;
}
void PrintMatrix(CvMat *Matrix, int Rows, int Cols,char* name)  
{
	if(name==NULL)
	{
		printf("----------------------------NonName-------\n",name);
	}
	else
	{
		printf("----------------------------%s-------\n",name);
	}
	int i=0,j=0; 
	for ( i= 0 ;i<Rows;i++) 
	{ 
		for ( j= 0 ;j<Cols;j++) 
		{ 
			printf( "%.2f " ,cvGet2D(Matrix,i,j).val[0]);
		}		 
		printf( "\n" ); 
	} 
} 
